let vue=new Vue({
    el:'.page-content',
    data:function () {
        return {
            result:{},
            role:{},
            searchName:'',
            params:{
                dataScope:'',
                oname:'',
                name:'',
                remarks:''
            },
            setting:{
                data:{//设置树的数据的配置
                    simpleData: {//简单数据格式配置  一维结构节点数组 不设置默认是多维结构数组
                        enable:true,  //开启使用简单数据格式
                        // idKey: 'id', //设置节点中的id属性key  默认
                        pIdKey: 'parentId' //设置父节点id属性key   与数据库中的字段需要对应
                    }
                },
                callback:{
                    onClick:this.onClick2
                },
                view:{//显示设置
                    //当显示某个节点/更新节点的时候，自动会调用字体设置
                    fontCss: this.fontCss1
                }
            },
            nodes:[]

        }
    },
    methods:{
        onClick2:function (event, treeId, treeNode) {
            this.params.oname=treeNode.name;
            $("#opneOrClose").removeClass('open')
        },
        initTree:function () {
            axios({
                url:'office/select'
            }).then(response=>{
                this.nodes=response.data.obj;
                //动态生成父节点 全部
                this.nodes[this.nodes.length] = {id:0,name:'全部机构'};
                //初始化树(dom节点对象,配置对象,节点数组)
                let zTreeObj = $.fn.zTree.init($('#pullDownTreeone'),this.setting,this.nodes);
                let nodes = zTreeObj.getNodes();//获取组装后的节点数组
            }).catch(error=>{
                layer.msg(error.message)
            })
        },
        search:function () {
            let zTreeObj = $.fn.zTree.getZTreeObj('pullDownTreeone');
            let nodes=zTreeObj.getNodes();
            nodes=zTreeObj.transformToArray(nodes);
            for (let i in nodes){
                nodes[i].highLight=false;
                zTreeObj.updateNode(nodes[i])
            }
            let searchName=null;
            if (this.searchName!=''){
                searchName=this.searchName;
            }
            let nodesFuzzy=zTreeObj.getNodesByParamFuzzy('name',searchName,null);
            for (let n in nodesFuzzy) {
                nodesFuzzy[n].highLight=true;
                zTreeObj.updateNode(nodesFuzzy[n])
            }
        },
        fontCss1:function (treeId,treeNode) {
            return treeNode.highLight?{color:'red'}:{color:'black'}
        },
        select:function (pageNum,pageSize) {
            axios({
                url:`role/select/${pageNum}/${pageSize}`,
                params:this.params
            }).then(response=>{
                this.result=response.data.obj
            })
        },
        selectAll:function (pageNum,pageSize) {
            this.params={};
            axios({
                url:`role/select/${pageNum}/${pageSize}`,
                params:this.params
            }).then(response=>{
                this.result=response.data.obj
            })
        },
        toRoleUser:function (id) {
            layer.id=id;
            layer.open({
                type:2,
                title: false,
                area: ['80%', '80%'],
                content: 'role/toRoleUser',
                end:(response)=>{
                }
            })
        },
        saveView:function (role) {
            layer.role=role;
            layer.open({
                type:2,
                title: false,
                area: ['80%', '80%'],
                content: 'role/saveView',
                end:(response)=>{
                    layer.msg(response.data.msg);
                    this.selectAll(1,5)
                }
            })
        }
    },
    created:function () {
        this.select(1,5);
        this.initTree()
    }
});